45

Explore Your Deductive Logic—Sudoku

45

STEP 8 continued

      Next l

    Next k

If notahomecount =​ 8 Then

    sbox(homerow, homecol) =​ putnumber

    Call updatecantbelist(putnumber, homerow, homecol)

    Cells(homerow, homecol) =​ sbox(homerow, homecol)

End If

End If

Next j

Next i

Next putnumber

3.4  3 BY 3 GRID INTERACTION

The next advanced algorithm we are going to look at explores the interaction between

two 3 by 3 grids that are adjacent to each other. If two adjacent 3 by 3 grids share the

same rows, and a certain number can only be in two of the three rows in the 3 by 3

grid and the adjacent 3 by 3 grid can also only have it in the same two of the three

rows, then the third 3 by 3 grid adjacent to it and sharing the same rows cannot have

that number in the same two rows. See example below.

2

2

2

2

5

6

9

4

2

2

2

2

COLUMN 1 2 3 4 5 6 7 8 9

9 8 7 6 5 4 3 2 1

ROW

FIGURE 3.4  Interaction between grids.

The code in steps 9 and 10 executes this algorithm, but with a slight twist. Instead of

working on the cells that share the same rows for a specific number (2 in the example

above), the code works on the row that does not have this number. This is easier because

we already have a matrix that stores what each cell is NOT (the “cantbelist”).